package com.ccx.coachsite.weibo.auth2;


import android.content.Context;

import com.ccx.coachsite.api.LocalAccessor;
import com.ccx.coachsite.weibo.auth2.net.Weibo;
import com.ccx.coachsite.weibo.auth2.vo.LoginUser;

public class WeiBoDBUtil {

	/**
	 * 获取登陆用户
	 * @param context
	 * @return
	 */
	public static LoginUser getLoginUser(Context context)
	{
		String sql="select * from "+Weibo.LoginTable.TABLE_NAME;
		
		return LocalAccessor.getInstance(context).getLoginUser(sql);
	}
	
	/**
	 * 添加登陆用户信息到数据库表
	 * @param context
	 * @param loginUser
	 * @return
	 */
	public static synchronized boolean addLoginUser(Context context,LoginUser loginUser)
	{
		//先清空
		deleteAllLoginUser(context);
		String sql="insert into "+Weibo.LoginTable.TABLE_NAME+"("+Weibo.LoginTable.USER_ID+","+
		Weibo.LoginTable.SCREEN_NAME+","+
		Weibo.LoginTable.ACCESS_TOKEN+","+
		Weibo.LoginTable.ACCOUNT+","+
		Weibo.LoginTable.PACKAGE_NAME+","+
		Weibo.LoginTable.LOGIN_TIME+") values(?,?,?,?,?,?)";

		Object[] obj=new Object[]{loginUser.getUid(),loginUser.getScreenName(),loginUser.getAccessToke(),loginUser.getAccount(),loginUser.getPackageName(),loginUser.getLoginTime()};
		LocalAccessor.getInstance(context).addLoginUser(sql, obj);
		boolean b=true;
		return b;
	}
	
	/**
	 * 删除所有登陆用户信息
	 * @param context
	 * @return
	 */
	public static synchronized boolean deleteAllLoginUser(Context context)
	{
		String sql="delete from "+Weibo.LoginTable.TABLE_NAME;
		LocalAccessor.getInstance(context).deleteAllLoginUser(sql);
		boolean b=true;
		return b;
	}
	
}
